<template>
	<view>
		<view class="topView">
			<view class="title">
				常见问题
			</view>
			<view class="title1">
				common problem
			</view>
			<view class="contentView">
				<view class="flex-row-flex-end">
					<image class="problemImage" src="@/static/image/icon-issue.png" mode="scaleToFill"></image>
				</view>
<!-- 				<view class="title2">
					常见问题
				</view> -->
				<view v-for="(item,index) in newsList" :key="index" :data-id="item.id" @tap="goPage">
					<view @click="itemClick(item)" class="item flex-row-space-between">
						<view class="itemTitle">
							{{item.title}}
						</view>
						<u-icon name="arrow-right" size="16" color="#666666"></u-icon>
					</view>
				</view>
			</view>

			<view @click="buttonClick()" class="button flex-row-center">
				联系客服（{{appConfig.kf_mobile}}）
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getCategoryList,
		getArticleList
	} from '../../api/new';
	import {
		loadingType
	} from '../../utils/type';
	import swipers from "../../components/swipers/swipers";
	import {
		loadingFun
	} from '@/utils/tools'
	import {
		mapGetters,
		mapActions
	} from 'vuex'

	export default {
		data() {
			return {
				active: 0,
				showLoading: true,
				categoryList: [],
				newsList: [],
				page: 1,
				status: loadingType.LOADING,
				bannerList: [],
				type: 0,
				mobile: '',
				// problemimg:this.$config.imgURL+'problemimg.png'
			};
		},

		components: {
			swipers,
		},

		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			//分类id
			this.id = options.id; //type存在则为帮助中心

			this.type = options.type || '';

			// if (this.type) {
			//   uni.setNavigationBarTitle({
			//     title: '帮助中心'
			//   });
			// } else {
			//   uni.setNavigationBarTitle({
			//     title: '商城资讯'
			//   });
			// }

			this.getCategoryListFun();
		},

		onReachBottom: function() {
			this.getArticleListFun();
		},

		computed: {
			...mapGetters(["appConfig"])

		},


		methods: {
			buttonClick() {
				console.log(this.appConfig.kf_mobile)
				var mobile = this.appConfig.kf_mobile
				uni.makePhoneCall({
					phoneNumber: `${mobile}`
				})
				// uni.makePhoneCall({
				// 	phoneNumber:'18500972540'
				// })
			},
			changeActive(e) {
				this.active = e;
				this.page = 1;
				this.newsList = [];
				this.status = loadingType.LOADING
				setTimeout(() => {
					this.getArticleListFun();
				}, 100);
			},

			getCategoryListFun() {
				getCategoryList({
					type: this.type
				}).then(res => {
					if (res.code == 1) {
						this.categoryList = res.data
						// this.getArticleListFun();
					}
				});
			},

			getArticleListFun() {
				let {
					active,
					page,
					newsList,
					status
				} = this;
				loadingFun(getArticleList, page, newsList, status, {
					type: this.type,
					id: active ? active.toString() : '',
					page_no: page
				}).then(res => {
					if (res) {
						this.page = res.page;
						this.newsList = res.dataList
						this.status = res.status
					}
				})
			},

			goPage(e) {
				let {
					id
				} = e.currentTarget.dataset;
				uni.navigateTo({
					url: `/pages/news_details/news_details?id=${id}&type=${this.type}`
				});
			}

		},

		onShow() {
			// this.changeActive()
		}
	};
</script>
<style lang="scss">
	.topView {
		width: 750rpx;
		height: 678rpx;
		background: linear-gradient(180deg, rgba(255, 110, 22, 0.5) 0%, rgba(255, 110, 22, 0) 100%);
	}

	.title {
		padding-top: 214rpx;
		margin-left: 96rpx;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 900;
		font-size: 56rpx;
		color: #3D3D3D;
		line-height: 82rpx;
	}

	.title1 {
		margin-left: 96rpx;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 20rpx;
		color: #999999;
		line-height: 28rpx;
		letter-spacing: 2px;
	}

	.contentView {
		padding-bottom: 20rpx;
		margin: 30rpx;
		margin-top: 60rpx;
		// background: #FFFFFF;
		border-radius: 15rpx 15rpx 15rpx 15rpx;
		opacity: 1;
	}

	.problemImage {
		margin-top: -200rpx;
		margin-right: 100rpx;
		width: 182rpx;
		height: 156rpx;
	}

	.title2 {
		// margin-top: 10rpx;
		margin-left: 30rpx;
		margin-bottom: 20rpx;
		font-size: 31rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 550;
		color: #333333;
	}

	.item {
		width: 100%;
		padding: 0 30rpx;
		height: 80rpx;
	}

	.button {
		font-size: 27rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		margin: 26rpx 20rpx;
		width: 710rpx;
		height: 86rpx;
		background: #FF6E16;
		border-radius: 36rpx 36rpx 36rpx 36rpx;
		opacity: 1;
	}
</style>